home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / QuickDraw3D 1.6 SDK / Mac SampleCode New for 1.6 / CompressedPixmapSample / Source / Misc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-05-18  |  2.1 KB  |  114 lines  |  [TEXT/CWIE]

  1. /****************************/
  2. /*      MISC ROUTINES       */
  3. /* By Brian Greenstone      */
  4. /****************************/
  5.  
  6.  
  7. /***************/
  8. /* EXTERNALS   */
  9. /***************/
  10. #include <Events.h>
  11. #include <Dialogs.h>
  12. #include <Processes.h>
  13. #include <NumberFormatting.h>
  14. #include <Timer.h>
  15. #include <math.h>
  16.  
  17. #include <QD3D.h>
  18. #include <QD3DErrors.h>
  19.  
  20. #include "myglobals.h"
  21. #include "misc.h"
  22.  
  23. extern    EventRecord    gTheEvent;
  24.  
  25.  
  26. /****************************/
  27. /*    CONSTANTS             */
  28. /****************************/
  29.  
  30. #define        ERROR_ALERT_ID        401
  31.  
  32. /**********************/
  33. /*     VARIABLES      */
  34. /**********************/
  35.  
  36.  
  37. /****************** DO SYSTEM ERROR ***************/
  38.  
  39. void ShowSystemErr(long err)
  40. {
  41. Str255        numStr;
  42.  
  43.     NumToString(err, numStr);
  44.     DoAlert (numStr);
  45.     CleanQuit();
  46. }
  47.  
  48. /*********************** DO ALERT *******************/
  49.  
  50. void DoAlert(Str255 s)
  51. {
  52.     ParamText(s,NIL_STRING,NIL_STRING,NIL_STRING);
  53.     NoteAlert(ERROR_ALERT_ID,nil);
  54. }
  55.         
  56. /*********************** DO FATAL ALERT *******************/
  57.  
  58. void DoFatalAlert(Str255 s)
  59. {
  60.     ParamText(s,NIL_STRING,NIL_STRING,NIL_STRING);
  61.     NoteAlert(ERROR_ALERT_ID,nil);
  62.     CleanQuit();
  63. }
  64.  
  65. /************ CLEAN QUIT ***************/
  66.  
  67. void CleanQuit(void)
  68. {
  69.     ExitToShell();
  70. }
  71.  
  72.  
  73.  
  74. /******************* FLOAT TO STRING *******************/
  75.  
  76. void FloatToString(float num, Str255 string)
  77. {
  78. Str255    sf;
  79. long    i,f;
  80.  
  81.     i = num;                        // get integer part
  82.     
  83.     
  84.     f = (fabs(num)-fabs((float)i)) * 10000;        // reduce num to fraction only & move decimal --> 5 places    
  85.  
  86.     if ((i==0) && (num < 0))        // special case if (-), but integer is 0
  87.     {
  88.         string[0] = 2;
  89.         string[1] = '-';
  90.         string[2] = '0';
  91.     }
  92.     else
  93.         NumToString(i,string);        // make integer into string
  94.         
  95.     NumToString(f,sf);                // make fraction into string
  96.     
  97.     string[++string[0]] = '.';        // add "." into string
  98.     
  99.     if (f >= 1)
  100.     {
  101.         if (f < 1000)
  102.             string[++string[0]] = '0';    // add 1000's zero
  103.         if (f < 100)
  104.             string[++string[0]] = '0';    // add 100's zero
  105.         if (f < 10)
  106.             string[++string[0]] = '0';    // add 10's zero
  107.     }
  108.     
  109.     for (i = 0; i < sf[0]; i++)
  110.     {
  111.         string[++string[0]] = sf[i+1];    // copy fraction into string
  112.     }
  113. }
  114.